/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef __L_MEASUREMENT_H__
#define __L_MEASUREMENT_H__

#include <string_view>
#include <lua.hpp>
#include "luawrapper.h"
#include "common.h"
#include "measurements/measurement.h"

class LMeasurement {
public:
    uint8_t  index;
    string   hashAlgorithm;
    string   measurementType;
    string   measurement;
    uint64_t lastUpdated;
    bool     partOfSummaryHash;
    string   securityVersionNumber;

    LMeasurement(unique_ptr<Measurement>& meas)
    {
        index                 = meas->index;
        hashAlgorithm         = meas->hashAlgorithm;
        measurementType       = meas->measurementType;
        measurement           = meas->measurement;
        lastUpdated           = meas->lastUpdated;
        partOfSummaryHash     = meas->partOfSummaryHash;
        securityVersionNumber = meas->securityVersionNumber;
    };
    ~LMeasurement() = default;

    uint8_t get_index()
    {
        return this->index;
    }

    std::string_view get_hash_algorithm() const
    {
        return this->hashAlgorithm;
    }

    std::string_view get_measurement_type() const
    {
        return this->measurementType;
    }

    std::string_view get_measurement() const
    {
        return this->measurement;
    }

    uint64_t get_last_updated() const
    {
        return this->lastUpdated;
    }

    bool get_part_of_hash() const
    {
        return this->partOfSummaryHash;
    }

    std::string_view get_security_version_number() const
    {
        return this->securityVersionNumber;
    }

    static void register_to(lua_State *L, luawrap::stack_table &t)
    {
        luawrap::restore_stack_top _s(L);

        auto cls = luawrap::lua_class<LMeasurement>(L);
        cls.def_property("index", c_func_wrap(L, LMeasurement::get_index));
        cls.def_property("hashAlgorithm", c_func_wrap(L, LMeasurement::get_hash_algorithm));
        cls.def_property("measurementType", c_func_wrap(L, LMeasurement::get_measurement_type));
        cls.def_property("measurement", c_func_wrap(L, LMeasurement::get_measurement));
        cls.def_property("lastUpdated", c_func_wrap(L, LMeasurement::get_last_updated));
        cls.def_property("partOfSummaryHash", c_func_wrap(L, LMeasurement::get_part_of_hash));
        cls.def_property("securityVersionNumber", c_func_wrap(L, LMeasurement::get_security_version_number));

        t.set("Measurement", cls);
    }
};

#endif // __L_MEASUREMENT_H__